/*
 * base.h
 *
 *  Created on: Jun 1, 2014
 *      Author: Lhmily
 */

#ifndef BASE_H_
#define BASE_H_

/*
 * Include standard headers
 */
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <netdb.h>
#include <signal.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "skel.h"

#define TRUE 1
#define FALSE 0
#define NLISTEN 5 /* max waiting connections*/
#define NSMB 5 /* number shared memory bufs*/
#define SMBUFSZ 256 /* size of shared memory buf*/

extern char *program_name; /* for error*/
#ifdef __SVR4
#define bzero(b,n) memset( ( b ),0,( n ) )
#endif

void error(int status, int err, char *fmt, ...);
void set_address(char *hname, char *sname, struct sockaddr_in *sap,
		char *protocol);
SOCKET tcp_server(char *hname, char *sname);
SOCKET tcp_client(char *hname, char *sname);
SOCKET udp_server(char *hname, char *sname);
SOCKET udp_client(char *hname, char *sname, struct sockaddr_in *sap);

int readn(SOCKET fd, char *bp, size_t len);
int readvrec(SOCKET fd, char *bp, size_t len);
#endif /* BASE_H_ */
